﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WI.CandidateManager.Business.Objects;
using WI.CandidateManager.Common.Data.Entities;

namespace CandidateManager.Areas.Coach.Controllers
{
    /// <summary>
    /// Controller for working with coach's profile.
    /// </summary>
    public class ProfileController : CandidateManager.Controllers.AutorizeBaseController
    {
        /// <summary>
        /// Show user profile.
        /// </summary>
        /// <returns>View of coach profile.</returns>
        [Authorize]
        public ActionResult Detail()
        {
            CoachBO coachBO = new CoachBO();
            var ob = coachBO.DisplayCoachProfile();

            return View(ob);
        }

        /// <summary>
        /// Get object of Coach for changing user profile.
        /// </summary>
        /// <param name="id">Coach id.</param>
        /// <returns>View for changing coach profile.</returns>
        [HttpGet]
        [Authorize]
        public ActionResult Edit(long UserId)
        {
            CoachBO coachBO = new CoachBO();
            var coach = coachBO.GetCoachProfile(UserId);

            return View(coach);
        }

        /// <summary>
        /// Send coach object to logic for editing profile.
        /// </summary>
        /// <param name="coach">Coach object.</param>
        /// <returns></returns>
        [HttpPost]
        [Authorize]
        public ActionResult Edit(long UserId, WI.CandidateManager.Common.Data.Entities.Coach coach)
        {
            CoachBO coachBO = new CoachBO();

            if (coachBO.ChangeCoachProfile(UserId, coach))
            {
                return RedirectToAction("Detail", "Profile");
            }

            return View(coach);
        }
    }
}
